package com.code.mapper;

import com.code.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 商城用户信息表 Mapper 接口
 * </p>
 *
 * @author guanfenga@yonyou.com
 * @since 2022-08-23
 */
//@Repository
//@Mapper
public interface UserMapper extends BaseMapper<User> {
    /**
     * 查询用户
     * @param page
     * @param limit
     * @param user
     * @return
     */
    @Select("SELECT * FROM mall_user order by createTime desc limit #{been} , #{after}")
    List<User> findUserPage(@Param("been") Integer page, @Param("after") Integer limit, User user);

    /**
     * 校验用户信息
     * @param username
     * @param pass
     * @return
     */
    @Select("select * from mall_user where (userName = #{username}  or phone = #{username} )  and password = #{pass}")
    User checkedUserAndPass(@Param("username") String username, @Param("pass") String pass);

    /**
     * 查询所有用户信息用于 React 框架
     * @return
     */
    @Select("SELECT * from mall_user u ORDER BY u.createTime DESC")
    List<User> queryBasicUserAll();

    @Insert("INSERT INTO mall_user(headPortraitUrl) VALUES(#{headPortraitUrl})")
    int uploadInfo(User user);

    @Select("SELECT * from mall_user u where u.userName = #{userName}")
    User queryUserName(@Param("userName") String userName);
}
